<?php include $this->templateDir .'common/header.php';?>
<style>
    .roleListMain .layui-unselect span{color: #5FB878;font-weight: bolder} </style>
<body style="padding: 10px;">
<form class="layui-form layui-form-pane">
    <div class="layui-form-item" >
        <label class="layui-form-label">角色名称</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="title" lay-verify="required" >
        </div>
    </div>

    <div class="layui-form-item" pane="">
        <div class="layui-inline">
            <label class="layui-form-label">权限菜单</label>
            <!-- 循环出所有一级菜单-->
            <?php
            foreach ($this->datas  as $k=>$v) { ?>
            <div class="layui-input-block">
                <div class="roleList">
                    <div class="roleListMain">
                         <input type="checkbox" name="menu[<?php  echo  $v['mid']?>]" lay-skin="primary" title="<?php echo $v['title']?>">
                    </div>
                <!-- 循环出所有二级菜单-->
                    <div class="roleListSon">
                    <?php if(is_array($v['children'])){ foreach ($v['children'] as $keychild => $vchild) {  ?>
                        <input type="checkbox" name="menu[<?php echo $vchild['mid']?>]" lay-skin="primary" title="|----<?php echo $vchild['title']?>">
                     <?php } } ?>
                    </div>
                    <hr>
                </div>
            </div>
             <?php  } ?>
        </div>
    </div>
<div class="layui-form-item">
    <div class="layui-input-block">
        <button class="layui-btn" id="graceSubBtn" lay-submit="" lay-filter="*">添加角色</button>
    </div>
</div>
</form>
</body>
</html>
<script type="text/javascript">
    layui.use(['form','layer'],function(){
        var form = layui.form;
        $ = layui.jquery;
        layer = layui.layer;

        // 保存
        form.on('submit(*)', function(data){
            // 提交操作
            var saveUrl ='<?php echo u("role","add");?>';
            $.post(saveUrl,data.field,function(res){
                if(res.status == "ok"){
                    layer.msg(res.data,{'icon':1});
                    setTimeout(function(){parent.window.location.reload();},1000);
                }else{
                     layer.msg(res.data,{'icon':2});
                }
            },'json');
            return false;
        });
    });
</script>